<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="消息来源（群）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgGroup">
              <a-input v-model="model.msgGroup" placeholder="请输入消息来源（群）"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerName">
              <a-input v-model="model.customerName" placeholder="请输入客户名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户信息内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgText">
              <a-textarea v-model="model.msgText" rows="4" placeholder="请输入客户信息内容" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgtype">
              <a-input v-model="model.msgtype" placeholder="请输入消息类型"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="供应商回复内容"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="supplierReply"
            >
              <a-input v-model="model.supplierReply" placeholder="请输入供应商回复内容"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确认回复内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comfirmReply">
              <a-input v-model="model.comfirmReply" placeholder="请输入确认回复内容"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息接收方列表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tolist">
              <a-textarea v-model="model.tolist" rows="4" placeholder="请输入消息接收方列表" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息发送时间戳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgtime">
              <a-input v-model="model.msgtime" placeholder="请输入消息发送时间戳"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息发送时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgDateTime">
              <j-date placeholder="请选择消息发送时间" v-model="model.msgDateTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgid">
              <a-input v-model="model.msgid" placeholder="请输入消息id"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息动作" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="action">
              <a-input v-model="model.action" placeholder="请输入消息动作"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息发送方id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgfrom">
              <a-input v-model="model.msgfrom" placeholder="请输入消息发送方id"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="群聊消息的群id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roomid">
              <a-input v-model="model.roomid" placeholder="请输入群聊消息的群id"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="回复时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="replyTime">
              <j-date placeholder="请选择回复时间" v-model="model.replyTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="回复人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="replyer">
              <a-input v-model="model.replyer" placeholder="请输入回复人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否完成" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isComplete">
              <a-input v-model="model.isComplete" placeholder="请输入是否完成"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'WechatSessionForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/wechatSession/wechatSession/add',
        edit: '/wechatSession/wechatSession/edit',
        queryById: '/wechatSession/wechatSession/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>
